package com.jsbb.controller.sys;

import com.jsbb.annotation.ApiLog;
import com.jsbb.common.Message;
import com.jsbb.dto.sys.*;
import com.jsbb.service.sys.SysUserService;
import com.jsbb.vo.PageVo;
import com.jsbb.vo.sys.SysUserDetailVo;
import com.jsbb.vo.sys.SysUserListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理Controller
 *
 * @author w
 * @date 2021-03-05
 */
@Slf4j
@RestController
@RequestMapping("/sys/user")
@ApiLog("用户管理")
@Api(tags = {"2.1 系统管理-用户管理"})
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/list")
    @ApiOperation(value = "获取列表")
    public Message<PageVo<SysUserListVo>> list(@Validated @RequestBody SysUserQueryDto queryDto) {
        PageVo<SysUserListVo> pageVo = sysUserService.list(queryDto);
        return Message.success(pageVo);
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取详情")
    public Message<SysUserDetailVo> get(@PathVariable("id") Long id) {
        SysUserDetailVo userVo = sysUserService.get(id);
        return Message.success(userVo);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增")
    public Message save(@Validated @RequestBody SysUserSaveDto saveDto) {
        sysUserService.save(saveDto);
        return Message.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Message update(@Validated @RequestBody SysUserUpdateDto updateDto) {
        sysUserService.update(updateDto);
        return Message.success();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public Message delete(@PathVariable("id") Long id) {
        sysUserService.delete(id);
        return Message.success();
    }

    @PostMapping("/data/update")
    @ApiOperation(value = "个人中心-修改基本资料")
    public Message baseDataUpdate(@Validated @RequestBody PersonalDataUpdateDto updateDto) {
        sysUserService.baseDataUpdate(updateDto);
        return Message.success();
    }

    @PostMapping("/pwd/update")
    @ApiOperation(value = "个人中心-修改密码")
    public Message pwdUpdate(@Validated @RequestBody PwdUpdateDto updateDto) {
        sysUserService.pwdUpdate(updateDto);
        return Message.success();
    }
}
